博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python之路 jQuery学习笔记
阅读量:4593 次
发布时间:2019-06-09

本文共 12403 字,大约阅读时间需要 41 分钟。

jQuery


一、选择器与筛选器

1 3.1.1 基本选择器       2  3 1 4 $("*")  $("#id")   $(".class")  $("element")  $(".class,p,div") 5 3.1.2 层级选择器       6  7 1 8 $(".outer div")  $(".outer>div")   $(".outer+div")  $(".outer~div") 9 3.1.3 基本筛选器      10 11 112 $("li:first")  $("li:eq(2)")  $("li:even") $("li:gt(1)")13 3.1.4 属性选择器    14 15 116 $('[id="div1"]')   $('["alex="sb"][id]')17 3.1.5 表单选择器     18 19 120 $("[type='text']")----->$(":text")         注意只适用于input标签  : $("input:checked")
基本选择器

 

1 $("li").eq(2)  $("li").first()  $("ul li").hasclass("test")
过滤选择器
1 $("div").children(".test")     $("div").find(".test")  2                                3  $(".test").next()    $(".test").nextAll()    $(".test").nextUntil() 4                            5  $("div").prev()  $("div").prevAll()  $("div").prevUntil()   6                         7  $(".test").parent()  $(".test").parents()  $(".test").parentUntil() 8 9  $("div").siblings()
查找选择器

 

二、操作元素(属性,css,文档处理)

1、属性操作

1 --------------------------属性 2 $("").attr(); 3 $("").removeAttr(); 4 $("").prop(); 5 $("").removeProp(); 6 --------------------------CSS类 7 $("").addClass(class|fn) 8 $("").removeClass([class|fn]) 9 --------------------------HTML代码/文本/值10 $("").html([val|fn])11 $("").text([val|fn])12 $("").val([val|fn|arr])13 ---------------------------14 $("").css("color","red")
1 是否可见 2 是否可见 3  4  5  6 
注意:

 

2、文档处理

1 //创建一个标签对象 2     $("

") 3 4 5 //内部插入 6 7 $("").append(content|fn) ----->$("p").append("Hello"); 8 $("").appendTo(content) ----->$("p").appendTo("div"); 9 $("").prepend(content|fn) ----->$("p").prepend("Hello");10 $("").prependTo(content) ----->$("p").prependTo("#foo");11 12 //外部插入13 14 $("").after(content|fn) ----->$("p").after("Hello");15 $("").before(content|fn) ----->$("p").before("Hello");16 $("").insertAfter(content) ----->$("p").insertAfter("#foo");17 $("").insertBefore(content) ----->$("p").insertBefore("#foo");18 19 //替换20 $("").replaceWith(content|fn) ----->$("p").replaceWith("Paragraph. ");21 22 //删除23 24 $("").empty()25 $("").remove([expr])26 27 //复制28 29 $("").clone([Even[,deepEven]])

* clone操作:

1  2  3  4     
5 Title 6 7 8 9
10
11
12
13
14
15 16 17 32 33
clone应用 复制样式条

 

3、css操作

1 CSS 2         $("").css(name|pro|[,val|fn]) 3     位置 4         $("").offset([coordinates]) #偏移量,是个对象,有两属性(top、left:相当视口的偏移顶部、左侧多少,数值)$("").offset().top; 5         $("").position()  #相对于已经定位的父亲标签的偏移量,两属性(top、left) 6         $("").scrollTop([val]) 7         $("").scrollLeft([val]) 8     尺寸 9         $("").height([val|fn])  #获取标签(内容)高度,不计padding、border10         $("").width([val|fn])  #获取标签(内容)宽度11         $("").innerHeight()  #获取高度,包括padding12         $("").innerWidth()  #获取宽度,包括padding13         $("").outerHeight([soptions]) #获取高度 包括padding、border14         $("").outerWidth([options])   #获取宽度 包括padding、border15 16 特别的:17         $("").outerWidth(true)  #获取宽度,包括padding、border、margin18         $("").outerWidth(“300px”)  #设置宽度

 

4、事件

1 页面载入 2     ready(fn)  //当DOM载入就绪可以查询及操纵时绑定一个要执行的函数。 3     $(document).ready(function(){}) -----------> $(function(){}) 4  5 事件处理 6     $("").on(eve,[selector],[data],fn)  // 在选择元素上绑定一个或多个事件的事件处理函数。 7  8     //  .on的selector参数是筛选出调用.on方法的dom元素的指定子元素,如: 9     //  $('ul').on('click', 'li', function(){console.log('click');})就是筛选出ul下的li给其绑定10     //  click事件;11 12     [selector]参数的好处:13         好处在于.on方法为动态添加的元素也能绑上指定事件;如:14 15         //$('ul li').on('click', function(){console.log('click');})的绑定方式和16         //$('ul li').bind('click', function(){console.log('click');})一样;我通过js给ul添加了一个17         //li:$('ul').append('
  • js new li
  • ');这个新加的li是不会被绑上click事件的18 19 //但是用$('ul').on('click', 'li', function(){console.log('click');}方式绑定,然后动态添加20 //li:$('ul').append('
  • js new li
  • ');这个新生成的li被绑上了click事件21 22 [data]参数的调用:23 function myHandler(event) {24 alert(event.data.foo);25 }26 $("li").on("click", {foo: "bar"}, myHandler)
  •  

    5、动画效果

    #显示 隐藏$("").hide(1000)  #隐藏,参数1000:1秒内完成隐藏$("").show(1000)  #显示,参数1000:1秒内完成显示$("").toggle(1000)  #隐藏与显示切换,参数1000:1秒内完成隐藏或显示#滑动显示 或 隐藏$("").slidedown(1000)  #滑动的效果显示$("").slideup(1000)    #滑动的效果隐藏$("").toggle(1000)    #滑动的效果显示或隐藏#淡入淡出$("").fadeIn(1000)    #淡入$("").fadeOut(1000)   #淡出$("").fadeTo(1000,0.4)    #透明度,可自己设置 0.4:透明度40%$("").fadeToggle(1000)  #淡入淡出切换

     

    注意:上述操作带有回调函数:

    1  2  3  4     
    5 Title 6 7 8 9 10 11

    helloworld helloworld helloworld

    12 13 14 15 23 24
    动画 回调函数

     

     三、实例汇集

    1、左侧菜单

    1  2  3  4     
    5 left_menu 6 7 32 33 34 35
    36
    63
    64 65
    66 67 75 76 77 78
    左侧菜单

     

     

    2、tab切换

    1  2  3  4     
    5 tab 6 14 50 51 52
    53
    58
    59
    内容一
    60
    内容二
    61
    内容三
    62
    63 64
    65 66
    tab切换

     

     

    3、全选 反选

    1  2  3  4     
    5 Title 6 7 67 68 69 70 71 72 73 74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    111
    222
    333
    444
    92 93 94 95 96
    全反选

     

     

    4、模态对话框

    1  2  3  4     
    5 Title 6 38 39 40
    41
    42
    43 44
    45
    46
    47
    48 49 50 51 64 65
    模态对话框

     

     

    5、监听窗口滚轮事件 返回顶部

    1  2  3  4     
    5 Title 6 7 34 68 69 70
    71

    hello

    72

    hello

    73

    hello

    74

    hello

    75

    hello

    76

    hello

    77

    hello

    78

    hello

    79

    hello

    80

    hello

    81

    hello

    82

    hello

    83

    hello

    84

    hello

    85

    hello

    86

    hello

    87

    hello

    88

    hello

    89 90
    91
    92
    93
    返回顶部
    94 95
    返回顶部

     

     

    6、滚动菜单

    1   2   3   4     
    5 6 97 98 99 100
    101
    102
    107
    120 121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131 132
    133

    第一章

    134
    135
    136

    第二章

    137
    138
    139

    第三章

    140
    141
    142
    143
    144 145 146 186 187 188 189
    滚动菜单

     

     

    7、面板拖动

    1  2  3  4     
    5 6 7 8
    9
    10 标题11
    12
    13 内容14
    15
    16 17 49 50
    面板拖动

     

     

    8、放大镜

    1   2   3   4     
    5 bigger 6 50 51 52 53
    54
    55
    56
    57 58
    59
    60
    61
    62 63
    64 65 66 67 135 136
    放大镜

     

     

    9、动画效果

     显示隐藏

    1  2  3  4     
    5 Title 6 7 24
    25 26 27 28 29

    hello

    30 31 32 33 34 35
    显示隐藏

     滑动

    1  2  3  4     
    5 Title 6 7 20 30 31 32 33
    出现
    34
    隐藏
    35
    toggle
    36 37
    helloworld
    38 39 40
    滑动

     淡入淡出

    1  2  3  4     
    5 Title 6 7 32 33 34 35 36 37 38 39 40
    41 42 43
    淡入淡出

     

    10、轮播图

        
    Title
    • 1
    • 2
    • 3
    • 4
    <
    >
    轮播图

     

    11、瀑布流

    1)自定义templatetags:

    from django import templatefrom django.utils.safestring import mark_safefrom django.template.base import resolve_variable, Node, TemplateSyntaxErrorregister = template.Library()@register.filterdef detail1(value,arg):    """    查看余数是否等于remainder arg="1,2"    :param counter:    :param allcount:    :param remainder:    :return:    """    allcount, remainder = arg.split(',')    allcount = int(allcount)    remainder = int(remainder)    if value%allcount == remainder:        return True    return False
    templatetags

     

    2)前端html:

    {% load xx %}    
    {
    % for i in img_list %} {
    % if forloop.counter|detail1:"4,1" %}
    {
    { forloop.counter }}
    {
    % endif %} {
    % endfor %}
    {
    % for i in img_list %} {
    % if forloop.counter|detail1:"4,2" %}
    {
    { forloop.counter }}
    {
    % endif %} {
    % endfor %}
    {
    % for i in img_list %} {
    % if forloop.counter|detail1:"4,3" %}
    {
    { forloop.counter }}
    {
    % endif %} {
    % endfor %}
    {
    % for i in img_list %} {
    % if forloop.counter|detail1:"4,0" %}
    {
    { forloop.counter }}
    {
    % endif %} {
    % endfor %}
    View Code

     

    转载于:https://www.cnblogs.com/Eric15/articles/9214710.html

    你可能感兴趣的文章
    加减乘除混合版
    查看>>
    linux基础6-bash shell编程
    查看>>
    php 语法
    查看>>
    回顾MySpace架构的坎坷之路
    查看>>
    ubuntu系统无eth0网卡解决办法
    查看>>
    六.计算机网络互联基础
    查看>>
    JS兼容各个浏览器的本地图片上传即时预览效果
    查看>>
    JS编写日历控件(支持单日历 双日历 甚至多日历等)
    查看>>
    ### 学习《C++ Primer》- 6
    查看>>
    IOS中实现单例
    查看>>
    Math 对象
    查看>>
    [luoguP1877] [HAOI2012]音量调节(DP)
    查看>>
    重磅 | 2017年深度学习优化算法研究亮点最新综述火热出炉
    查看>>
    clipboard.js 介绍
    查看>>
    (二)程序中的内存&&栈
    查看>>
    一个实例来见证LINGO的强大
    查看>>
    C# — WinForm TCP连接之服务器端
    查看>>
    HTML8
    查看>>
    asp.net 导出excel 以及插入图片
    查看>>
    揭密Google Map的工作原理(转)
    查看>>